package com.czy.tank.utils;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

/********************************************************************
 * @brief 图片处理类
 * @version 0.1
 * @date 2022年08月31日 15:47
 * @author changziyang
 ********************************************************************/
public class ImageUtil {

    /*************************************************
     * 方法描述:图片处理 调整图片角度
     * @param bufferedimage
     * @param degree
     * @return java.awt.image.BufferedImage
     * @author create: 人员:【changziyang】类型:【新增方法】日期:【2022/9/1 10:28】
     * @author modify:
     **************************************************/
    public static BufferedImage rotateImage(final BufferedImage bufferedimage, final int degree) {
        int w = bufferedimage.getWidth();
        int h = bufferedimage.getHeight();
        int type = bufferedimage.getColorModel().getTransparency();
        BufferedImage img;
        Graphics2D graphics2d;
        (graphics2d = (img = new BufferedImage(w, h, type)).createGraphics()).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        graphics2d.rotate(Math.toRadians(degree), w / 2, h / 2);
        graphics2d.drawImage(bufferedimage, 0, 0, null);
        graphics2d.dispose();
        return img;
    }
}
